from flask import Flask,jsonify,request
from flask_cors import CORS
from data_search import searcher

app = Flask(__name__)
CORS(app)

@app.route('/')
def hello_world():
    return 'Hello, World!'

@app.route('/search',methods = ["POST"])
def search_data():
    #获取前端的数据
    json_data = request.get_json()
    print(json_data)
    # 获取头部的搜索数据
    search_query = json_data['keyword']
    selected_education_level = json_data['educationLevel']
    selected_province = json_data['province']
    selected_city = json_data['city']
    # 把search_query列表化
    search_query = search_query.split()
    print(search_query)
    result = searcher(selected_education_level,search_query,selected_city,selected_province)

    print(result)
    return jsonify({
        'message':'success',
        'data':result
    },200)

if __name__ == '__main__':
    app.run(debug=True, host='127.0.0.1')